package com.colabo.j2ee.web.core.exception;

import java.io.Serializable;

/**
 * 消息定义
 */
public class ReadableMessage implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String LVL_INFO = "I";

	public static final String LVL_WARN = "W";

	public static final String LVL_ERROR = "E";

	protected String key;

	protected Object[] params;

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public Object[] getParams() {
		return params;
	}

	public void setParams(Object[] params) {
		this.params = params;
	}

	public ReadableMessage(String key, Object[] params) {
		this.key = key;
		this.params = params;
	}

	public ReadableMessage(String key) {
		this.key = key;
	}

	public String getErrorType() {
		return key.substring(0, 1);
	}

	/**
	 * 取出异常描述，通常是从配置好的属性文件中获取
	 */
	public String getMsgInfo() {
		if (getParams() != null) {
			return ExpMessageUtil.getMessage(getKey(), getParams());
		} else {
			return ExpMessageUtil.getMessage(getKey());
		}

	}
}
